package com.neuedu.spring.aop;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.aop.AfterAdvice;
import org.springframework.aop.BeforeAdvice;
import org.springframework.aop.MethodBeforeAdvice;
import org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint;

import java.lang.reflect.Method;


public class MyAdvice implements MethodBeforeAdvice {




    public void before() {
        System.out.println("开启事务，提交事务");
    }

    public void after() {
        System.out.println("关闭事务，提交事务");
    }


//    public void afterThrowing(Throwable throwable){
//        System.out.println("MyAdvice.afterThrowing"+throwable);
//    }


    public void around(ProceedingJoinPoint joinPoint) {


        System.out.println("Signature:" + joinPoint.getSignature().toLongString());
        System.out.println("getThis:\t" + joinPoint.getThis());
        System.out.println("getTarget:\t" + joinPoint.getTarget());
        //方法之前
        System.out.println("aroundBefore");
        try {
            joinPoint.proceed(); //调用原始的方法
        } catch (Throwable throwable) {
            throwable.printStackTrace();
        }
        //方法之
        System.out.println("arondAfter");
    }

    public void afterReturning(Object returnObj) {
        System.out.println("MyAdvice.afterReturning" + returnObj);
    }


    public void before(Method method, Object[] args, Object target) throws Throwable {
        System.out.println("前置通知....  Advisor");
    }
}
